<template name="shareview">
	<view>
		<view class="cu-modal  " :class="modalName=='Image'?'show':''">
			<view class="cu-dialog nobg text-center shadow" style="width: 80%;">
				<view class="padding-lr" v-if="image">
					<image :src="image" mode="widthFix"></image>
				</view>
				<view class="text-center">
					<!-- #ifdef APP-VUE -->
					<view class="cu-btn blackbg1 sm text-black  round text-white lg margin-top " @tap="bc_code">保存</view>
					<!-- #endif -->
					<view class="cu-btn blackbg1 sm text-black  round text-white lg margin-top margin-left-sm" @tap="modalName=''">关闭</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			type: {
				type: String,
				default: 'member'
			}
		},
		created: function(e) {},
		data() {
			return {
				modalName: '',
				image: '',
				CLOUDPATH: this.$config.cloudPath,
				BASEPATH: this.$http.host(),
			}
		},
		methods: {
			show(param) {
				this.modalName = 'Image'
				if (this.image) {
					uni.hideLoading()
				} else {
					uni.showLoading({
						title: '海报生成中...',
						mask: true,
					})
					this.$http
						.post('get_poster', param)
						.then((response) => {
							this.image = response.data.data
							uni.hideLoading()
						})
						.catch((response) => {
							this.loading = false
							uni.hideLoading()
						})
				}

			},
			bc_code(){
				
				uni.showLoading({
					title: '保存中...',
				})
				let that = this;
				//console.log('保存二维码')
				uni.downloadFile({           //获得二维码的临时地址
					url:this.image,
					success:(res)=>{
						//console.log('获取url',res)
						if(res.statusCode == 200){
							uni.saveImageToPhotosAlbum({
								filePath:res.tempFilePath,//传入临时地址
								success: () => {
									this.$common.showError('保存成功')//封装的提示
								},
								fail : () => {
									this.$common.showError('保存失败')
								}
							})
							uni.hideLoading()
						}
					}
				})
			},
		},
	}
</script>

<style>
	.nobg {
		background: none;
	}
</style>
